var t = require("../../utils/config.js");

Page({
    data: {
        currentType: "day",
        isHideMore: !1,
        work: "",
        planWork: "",
        coordinationMatter: "",
        remark: "",
        imageUrl: ""
    },
    onLoad: function(t) {
        if (t.type) {
            var a = this;
            a.setData({
                currentType: t.type,
                isHideMore: !0
            });
            var e = JSON.parse(t.obj);
            "day" == t.type ? a.setData({
                work: e.todayFinishedWork,
                planWork: e.tomorrowPlanWork,
                coordinationMatter: e.coordinationMatter,
                remark: e.remark,
                imageUrl: e.imageUrl
            }) : "week" == t.type ? a.setData({
                work: e.thisWeekFinishedWork,
                planWork: e.nextWeekPlanWork,
                coordinationMatter: e.coordinationMatter,
                remark: e.remark,
                imageUrl: e.imageUrl
            }) : "month" == t.type && a.setData({
                work: e.thisMonthFinishedWork,
                planWork: e.nextMonthPlanWork,
                coordinationMatter: e.coordinationMatter,
                remark: e.remark,
                imageUrl: e.imageUrl
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    changeType: function(t) {
        this.setData({
            currentType: t.currentTarget.dataset.type
        });
    },
    getWork: function(t) {
        this.setData({
            work: t.detail.value
        });
    },
    getPlanWork: function(t) {
        this.setData({
            planWork: t.detail.value
        });
    },
    getCoordinationMatter: function(t) {
        this.setData({
            coordinationMatter: t.detail.value
        });
    },
    getRemark: function(t) {
        this.setData({
            remark: t.detail.value
        });
    },
    apply: function() {
        var a = this;
        if (a.data.work) if (a.data.planWork) if (a.data.coordinationMatter) {
            wx.showLoading({
                mask: !0
            });
            var e = {
                userId: wx.getStorageSync("userId"),
                serviceProviderId: wx.getStorageSync("serviceProviderId"),
                coordinationMatter: a.data.coordinationMatter,
                remark: a.data.remark
            }, o = "";
            "day" == a.data.currentType ? (e.todayFinishedWork = a.data.work, e.tomorrowPlanWork = a.data.planWork, 
            o = t.urlList.API_WORK_REPORT_ADD_DAILY) : "week" == a.data.currentType ? (e.thisWeekFinishedWork = a.data.work, 
            e.nextWeekPlanWork = a.data.planWork, o = t.urlList.API_WORK_REPORT_ADD_Weekly) : "month" == a.data.currentType && (e.thisMonthFinishedWork = a.data.work, 
            e.nextMonthPlanWork = a.data.planWork, o = t.urlList.API_WORK_REPORT_ADD_Monthly), 
            a.data.imageUrl ? wx.uploadFile({
                url: t.urlList.API_TOOLS_UPLOAD_FILE,
                filePath: a.data.imageUrl,
                name: "file",
                success: function(t) {
                    var a = JSON.parse(t.data);
                    200 == a.status ? (e.imageId = a.data.fileId, wx.request({
                        url: o,
                        method: "POST",
                        header: {
                            contentType: "application/json"
                        },
                        data: e,
                        success: function(t) {
                            wx.hideLoading(), 200 == t.data.status ? (wx.navigateBack(), wx.showToast({
                                title: "提交成功"
                            })) : wx.showToast({
                                title: t.data.message,
                                icon: "none"
                            });
                        }
                    })) : (wx.hideLoading(), wx.showToast({
                        title: t.data.message,
                        icon: "none"
                    }));
                }
            }) : wx.request({
                url: o,
                method: "POST",
                header: {
                    contentType: "application/json"
                },
                data: e,
                success: function(t) {
                    wx.hideLoading(), 200 == t.data.status ? (wx.navigateBack(), wx.showToast({
                        title: "提交成功"
                    })) : wx.showToast({
                        title: t.data.message,
                        icon: "none"
                    });
                }
            });
        } else wx.showToast({
            title: "请输入需协调事项",
            icon: "none"
        }); else wx.showToast({
            title: "day" == a.data.currentType ? "请输入明日工作计划" : "week" == a.data.currentType ? "请输入下周工作计划" : "下月工作计划",
            icon: "none"
        }); else wx.showToast({
            title: "day" == a.data.currentType ? "请输入今日完成工作" : "week" == a.data.currentType ? "请输入本周完成工作" : "请输入本月完成工作",
            icon: "none"
        });
    },
    previewImage: function(t) {
        var a = this;
        a.data.imageUrl && wx.previewImage({
            current: t.target.dataset.src,
            urls: [ a.data.imageUrl ]
        });
    },
    chooseImage: function() {
        var t = this;
        wx.chooseImage({
            count: 1,
            success: function(a) {
                console.log(a), t.setData({
                    imageUrl: a.tempFilePaths[0]
                });
            }
        });
    },
    goToWorkReportHistory: function() {
        wx.navigateTo({
            url: "workReportHistory?type=" + this.data.currentType
        });
    }
});